home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2001 May / SGI Freeware 2001 May - Disc 1.iso / dist / fw_qt.idb / usr / freeware / include / qabstractlayout.h.z / qabstractlayout.h
C/C++ Source or Header  |  2001-04-12  |  8KB  |  276 lines

  1. /****************************************************************************
  2. ** $Id: qt/src/kernel/qabstractlayout.h   2.3.0   edited 2001-01-26 $
  3. **
  4. ** Definition of the abstract layout base class
  5. **
  6. ** Created : 960416
  7. **
  8. ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
  9. **
  10. ** This file is part of the kernel module of the Qt GUI Toolkit.
  11. **
  12. ** This file may be distributed under the terms of the Q Public License
  13. ** as defined by Trolltech AS of Norway and appearing in the file
  14. ** LICENSE.QPL included in the packaging of this file.
  15. **
  16. ** This file may be distributed and/or modified under the terms of the
  17. ** GNU General Public License version 2 as published by the Free Software
  18. ** Foundation and appearing in the file LICENSE.GPL included in the
  19. ** packaging of this file.
  20. **
  21. ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
  22. ** licenses may use this file in accordance with the Qt Commercial License
  23. ** Agreement provided with the Software.
  24. **
  25. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  26. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  27. **
  28. ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
  29. **   information about Qt Commercial License Agreements.
  30. ** See http://www.trolltech.com/qpl/ for QPL licensing information.
  31. ** See http://www.trolltech.com/gpl/ for GPL licensing information.
  32. **
  33. ** Contact info@trolltech.com if any conditions of this licensing are
  34. ** not clear to you.
  35. **
  36. **********************************************************************/
  37.  
  38. #ifndef QABSTRACTLAYOUT_H
  39. #define QABSTRACTLAYOUT_H
  40.  
  41. #ifndef QT_H
  42. #include "qobject.h"
  43. #include "qsizepolicy.h"
  44. #include "qwidget.h"
  45. #endif // QT_H
  46.  
  47. #ifndef QT_NO_LAYOUT
  48.  
  49. class QMenuBar;
  50. class QWidget;
  51. struct QLayoutData;
  52. class QLayoutItem;
  53. class QLayout;
  54. class QSpacerItem;
  55. class QDomElement;
  56. class QConfigureLayoutEvent;
  57.  
  58. class Q_EXPORT QGLayoutIterator : public QShared
  59. {
  60. public:
  61.     virtual ~QGLayoutIterator();
  62.     virtual QLayoutItem *next() = 0;
  63.     virtual QLayoutItem *current() = 0;
  64.     virtual QLayoutItem *takeCurrent() = 0;
  65. };
  66.  
  67. class Q_EXPORT QLayoutIterator
  68. {
  69. public:
  70.     QLayoutIterator( QGLayoutIterator *i ) :it(i) {}
  71.     QLayoutIterator( const QLayoutIterator &i ) :it( i.it )
  72.     { if ( it ) it->ref(); }
  73.     ~QLayoutIterator() { if ( it && it->deref() ) delete it; }
  74.     QLayoutIterator &operator=( const QLayoutIterator &i )
  75.     {
  76.     if ( i.it ) i.it->ref();
  77.     if ( it && it->deref() ) delete it;
  78.     it = i.it;
  79.     return *this;
  80.     }
  81.     QLayoutItem *operator++() { return it ? it->next() : 0; }
  82.     QLayoutItem *current() { return it ? it->current() : 0; }
  83.     QLayoutItem *takeCurrent() { return it ? it->takeCurrent() : 0; }
  84.     void deleteCurrent();
  85. private:
  86.     QGLayoutIterator *it;
  87. };
  88.  
  89.  
  90. class Q_EXPORT QLayoutItem
  91. {
  92. public:
  93.     QLayoutItem( int alignment = 0 ) :align(alignment) {}
  94.     virtual ~QLayoutItem();
  95.     virtual QSize sizeHint() const = 0;
  96.     virtual QSize minimumSize() const = 0;
  97.     virtual QSize maximumSize() const = 0;
  98.     virtual QSizePolicy::ExpandData expanding() const =0;
  99.     virtual void setGeometry( const QRect& ) = 0;
  100.     virtual QRect geometry() const = 0;
  101.     virtual bool isEmpty() const = 0;
  102.     virtual bool hasHeightForWidth() const;
  103.     virtual int heightForWidth( int ) const;
  104.     virtual void invalidate();
  105.  
  106.     virtual QWidget *widget();
  107.     virtual QLayoutIterator iterator();
  108.     virtual QLayout *layout();
  109.     virtual QSpacerItem *spacerItem();
  110.  
  111.     int alignment() const { return align; }
  112.     virtual void setAlignment( int a );
  113. protected:
  114.     int align;
  115. };
  116.  
  117.  
  118. class Q_EXPORT QSpacerItem : public QLayoutItem
  119. {
  120.  public:
  121.     QSpacerItem( int w, int h,
  122.          QSizePolicy::SizeType hData=QSizePolicy::Minimum,
  123.          QSizePolicy::SizeType vData= QSizePolicy::Minimum )
  124.     :width(w), height(h), sizeP(hData, vData )
  125.     {}
  126.     void changeSize( int w, int h,
  127.         QSizePolicy::SizeType hData=QSizePolicy::Minimum,
  128.         QSizePolicy::SizeType vData=QSizePolicy::Minimum );
  129.     QSize sizeHint() const ;
  130.     QSize minimumSize() const ;
  131.     QSize maximumSize() const ;
  132.     QSizePolicy::ExpandData expanding() const;
  133.     bool isEmpty() const;
  134.     void setGeometry( const QRect& );
  135.     QRect geometry() const;
  136.     QSpacerItem *spacerItem();
  137. private:
  138.     int width, height;
  139.     QSizePolicy sizeP;
  140.     QRect rect;
  141. };
  142.  
  143.  
  144. class Q_EXPORT QWidgetItem : public QLayoutItem
  145. {
  146. public:
  147.     QWidgetItem( QWidget *w ) : wid(w) {}
  148.     QSize sizeHint() const ;
  149.     QSize minimumSize() const ;
  150.     QSize maximumSize() const ;
  151.     QSizePolicy::ExpandData expanding() const;
  152.     bool isEmpty() const;
  153.     void setGeometry( const QRect& ) ;
  154.     QRect geometry() const;
  155.     //void invalidate();
  156.     virtual QWidget *widget();
  157.  
  158.     bool hasHeightForWidth() const;
  159.     int heightForWidth( int ) const;
  160.  
  161.     const QSize &widgetSizeHint() const;
  162.  
  163. private:
  164.     //QSize cachedSizeHint;
  165.     QWidget *wid;
  166. };
  167.  
  168.  
  169. class Q_EXPORT QLayout : public QObject, public QLayoutItem
  170. {
  171.     Q_OBJECT
  172.     Q_ENUMS( ResizeMode )
  173.     Q_PROPERTY( int margin READ margin WRITE setMargin )
  174.     Q_PROPERTY( int spacing READ spacing WRITE setSpacing )
  175.     Q_PROPERTY( ResizeMode resizeMode READ resizeMode WRITE setResizeMode )
  176.  
  177. public:
  178.     QLayout( QWidget *parent, int margin=0, int space=-1,
  179.          const char *name=0 );
  180.     QLayout( QLayout *parentLayout, int space=-1, const char *name=0 );
  181.     QLayout( int space=-1, const char *name=0 );
  182.  
  183.     ~QLayout();
  184.  
  185.     int margin() const { return outsideBorder; }
  186.     int spacing() const { return insideSpacing; }
  187.  
  188.     virtual void setMargin( int );
  189.     virtual void setSpacing( int );
  190.  
  191.     enum { unlimited = QWIDGETSIZE_MAX };
  192. #if 1 //OBSOLETE
  193.     int defaultBorder() const { return insideSpacing; }
  194.     void freeze( int w, int h );
  195.     void freeze() { setResizeMode( Fixed ); }
  196. #endif
  197.  
  198.     enum ResizeMode { FreeResize, Minimum, Fixed };
  199.     void setResizeMode( ResizeMode );
  200.     ResizeMode resizeMode() const;
  201.  
  202. #ifndef QT_NO_MENUBAR
  203.     virtual void  setMenuBar( QMenuBar *w );
  204.     QMenuBar *menuBar() const { return menubar; }
  205. #endif
  206.  
  207.     QWidget *mainWidget();
  208.     bool isTopLevel() const { return topLevel; }
  209.  
  210.     virtual void setAutoAdd( bool );
  211.     bool autoAdd() const { return autoNewChild; }
  212.  
  213.     void invalidate();
  214.     QRect geometry() const;
  215.     bool activate();
  216.  
  217.     void add( QWidget *w ) { addItem( new QWidgetItem( w ) ); }
  218.     virtual void addItem ( QLayoutItem * ) = 0;
  219.  
  220.     QSizePolicy::ExpandData expanding() const;
  221.     QSize minimumSize() const;
  222.     QSize maximumSize() const;
  223.     void setGeometry( const QRect& )=0;
  224.     QLayoutIterator iterator()=0;
  225.     bool isEmpty() const;
  226.  
  227.     int totalHeightForWidth( int w ) const;
  228.     QSize totalMinimumSize() const;
  229.     QSize totalMaximumSize() const;
  230.     QSize totalSizeHint() const;
  231.     QLayout *layout();
  232.  
  233.     bool supportsMargin() const { return marginImpl; }
  234.     
  235.     void setEnabled( bool );
  236.     bool isEnabled() const;
  237.  
  238. protected:
  239.     bool  eventFilter( QObject *, QEvent * );
  240.     void addChildLayout( QLayout *l );
  241.     void deleteAllItems();
  242.  
  243.     void setSupportsMargin( bool );
  244.     QRect alignmentRect( const QRect& ) const;
  245. private:
  246.     void setWidgetLayout( QWidget *, QLayout * );
  247.     void init();
  248.     int insideSpacing;
  249.     int outsideBorder;
  250.     uint topLevel : 1;
  251.     uint autoMinimum : 1;
  252.     uint autoNewChild : 1;
  253.     uint frozen : 1;
  254.     uint activated : 1;
  255.     uint marginImpl : 1;
  256.     uint enabled : 1;
  257.     QRect rect;
  258.     QLayoutData *extraData;
  259. #ifndef QT_NO_MENUBAR
  260.     QMenuBar *menubar;
  261. #endif
  262. private:    // Disabled copy constructor and operator=
  263. #if defined(Q_DISABLE_COPY)
  264.     QLayout( const QLayout & );
  265.     QLayout &operator=( const QLayout & );
  266. #endif
  267.  
  268. };
  269.  
  270. inline void QLayoutIterator::deleteCurrent()
  271. {
  272.     delete takeCurrent();
  273. }
  274. #endif //QT_NO_LAYOUT
  275. #endif
  276.